<?php
namespace app\common\model;

use think\Model;
use think\Db;
class LearnBooks extends Model
{
    // 指定表名,不含前缀
    protected $name = 'learn_books';
    /**
     * @param array $arg
     * @param string $field
     */
    public function getListByArg(array $arg,$field='*')
    {
        return $this->where($arg)->field($field)->select();
    }
	
	 public function getListByArgOne(array $arg,$field='*')
    {
        return $this->where($arg)->field($field)->find();
    }

    public function getListInsert($arr,$listArr){
		$books = self::getListByArgOne(['identity_id'=>$arr['identity_id']]);
		if(empty($books->id)){
			$data = [
					'identity_id'=>$arr['identity_id'],
					'qbankid'=>$arr['qbankid'],
					'questions'=>$listArr,
					];
			$this->insert($data);
		} else {
			$data = [
					'qbankid'=>$arr['qbankid'],
					'questions'=>$listArr,
					'answer'=>'',
					];
			$this->where(['id'=>$books->id])->update($data);
		}
	}
}
